{
 "metadata": {
  "name": "",
  "signature": "sha256:ac2d018a76947a76be37d436946362fd811fd8cc1b376ae7e2f701fc98c0987c"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Manuscript Example"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import hgvs\n",
      "hgvs.__version__"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 1,
       "text": [
        "'0.3dev-283858cb6466'"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Parse an HGVS string into a Python structure"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import hgvs.parser \n",
      "hp = hgvs.parser.Parser()\n",
      "var_c1 = hp.parse_hgvs_variant('NM_182763.2:c.688+403C>T')\n",
      "var_c1, var_c1.posedit.pos.start"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 2,
       "text": [
        "(SequenceVariant(ac=NM_182763.2, type=c, posedit=688+403C>T),\n",
        " BaseOffsetPosition(base=688, offset=403, datum=1, uncertain=False))"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Open the UTA public data source for mapping and validation"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import hgvs.dataproviders.uta\n",
      "hdp = hgvs.dataproviders.uta.connect()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Project transcript variant NM_182763.2:c.688+403C>T\n",
      "<br>to GRCh37 primary assembly using splign alignments"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import hgvs.variantmapper\n",
      "vm = hgvs.variantmapper.AssemblyMapper(\n",
      "    hdp, assembly_name='GRCh37', alt_aln_method='splign')\n",
      "var_g = vm.c_to_g(var_c1)\n",
      "var_g"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "SequenceVariant(ac=NC_000001.10, type=g, posedit=150550916G>A)"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Project genomic variant to a new transcript"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "vm.relevant_transcripts(var_g)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 5,
       "text": [
        "['NM_182763.2', 'NM_021960.4', 'NM_001197320.1']"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "var_c2 = vm.g_to_c(var_g,'NM_001197320.1')\n",
      "var_c2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 6,
       "text": [
        "SequenceVariant(ac=NM_001197320.1, type=c, posedit=281C>T)"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Infer protein changes for these transcript variants"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "var_p1 = vm.c_to_p(var_c1)\n",
      "var_p2 = vm.c_to_p(var_c2)\n",
      "var_p1, var_p2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 7,
       "text": [
        "(SequenceVariant(ac=NP_877495.1, type=p, posedit=?),\n",
        " SequenceVariant(ac=NP_001184249.1, type=p, posedit=(Ser94Phe)))"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Format the results by \"stringification\""
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print(\"\"\"mapped {var_c1} ({var_p1})\n",
      "    to {var_c2} ({var_p2})\n",
      "   via {var_g}\"\"\".format(\n",
      "        var_c1=var_c1, var_p1=var_p1,\n",
      "        var_c2=var_c2, var_p2=var_p2,\n",
      "        var_g=var_g))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "mapped NM_182763.2:c.688+403C>T (NP_877495.1:p.?)\n",
        "    to NM_001197320.1:c.281C>T (NP_001184249.1:p.(Ser94Phe))\n",
        "   via NC_000001.10:g.150550916G>A\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Validate a variant"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import hgvs.validator\n",
      "import hgvs.exceptions\n",
      "vr = hgvs.validator.Validator(hdp=hdp)\n",
      "try:\n",
      "    vr.validate( hp.parse_hgvs_variant('NM_001197320.1:c.281C>T') )\n",
      "    vr.validate( hp.parse_hgvs_variant('NM_001197320.1:c.281A>T') )\n",
      "except hgvs.exceptions.HGVSError as e:\n",
      "    print(e)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "NM_001197320.1:c.281A>T: Variant reference does not agree with reference sequence\n"
       ]
      }
     ],
     "prompt_number": 9
    }
   ],
   "metadata": {}
  }
 ]
}